package com.thread.demo10.a1;
import java.util.Random;

public class Demo {

    private static ThreadLocal<Integer> threadData = new ThreadLocal<>();

    /**
     * @param args
     */
    public static void main(String[] args) {

        WordThread thread1 = new WordThread(threadData);
        WordThread thread2 = new WordThread(threadData);

        thread1.start();
        thread2.start();

        System.out.println(Thread.currentThread().getName()+" 执行完毕");

    }

}

class WordThread extends Thread {
    private ThreadLocal<Integer> mThreadData;

    public WordThread(ThreadLocal<Integer> threadData) {
        this.mThreadData = threadData;
    }

    /* (non-Javadoc)
     * @see java.lang.Thread#run()
     */
    @Override
    public void run() {
        super.run();
        System.out.println("WordThread:" + Thread.currentThread().getName());

        int dataIn = new Random().nextInt(10);

        mThreadData.set(dataIn);

        // 获取数据
        int dataOut = mThreadData.get();
        System.out.println(dataOut);

    }
}
